﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;

namespace Rifts.Creator
{
	/// <summary>
	/// Interaction logic for CreatorView.xaml
	/// </summary>
	public partial class CreatorView : UserControl
	{
		public CreatorView()
		{
			InitializeComponent();
			DataContextChanged += CreatorView_DataContextChanged;
			NavigationFrame.LoadCompleted += NavigationFrame_LoadCompleted;
		}

		public CreatorViewModel TypedDataContext
		{
			get { return (CreatorViewModel)DataContext; }
		}

		void NavigationFrame_LoadCompleted(object sender, NavigationEventArgs e)
		{
			var content = NavigationFrame.Content as FrameworkElement;
			if (content != null)
				content.DataContext = NavigationFrame.DataContext;
		}

		void CreatorView_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
		{
			if (DataContext is CreatorViewModel)
			{
				((CreatorViewModel)DataContext).SetNavigator(NavigationFrame);
				((CreatorViewModel)DataContext).FirstPage();
			}

		}
	}
}
